package com.example.service.impl;

import com.example.VO.BorrowRecordVO;
import com.example.mapper.BookMapper;
import com.example.mapper.BorrowRecordMapper;
import com.example.service.BorrowRecordService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @auth shanyue
 * @date 2025年06月06日16:02
 */
@Service
public class BorrowRecordsServiceImpl implements BorrowRecordService {

    @Resource
    private BorrowRecordMapper borrowRecordMapper;

    @Resource
    private BookMapper bookMapper;

    @Override
    public void returnBook(Integer recordId) {
        borrowRecordMapper.returnBook(recordId);
        Integer bookId = borrowRecordMapper.getBookIdByRecordId(recordId);

        if (bookId != null) {
            bookMapper.increaseStock(bookId);
        }
    }

    @Override
    public List<BorrowRecordVO> getBorrowRecordsByUserId(Integer userId) {
        return borrowRecordMapper.findByUserId(userId);
    }


}
